﻿@inject IDataCacheService _dataCacheService
@inject IHttpService _httpService
@inject IPageModelCatche<List<FavoriteFolderOverviewModel>> _pageModelCatche

@if (Model.Any())
{
    <CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Catalogs.ToIconString()" Title="相关目录" Outline Collapable>
     @foreach (var item in Model)
        {
            <div class="mb-3">
                <MDCard Href="@("/favoritefolders/index/" + item.Id)" class="on-surface-text h-100">
                    <div style="display: flex; align-items: center;">
                        <div style="display: flex;">
                            <img loading="lazy" style=" width: 160px; " src="@item.MainImage" alt="@item.Name">
                        </div>
                        <div class="me-2 ms-2">
                            <div class="text-truncate-1 title-large">@item.Name</div>
                            <div class="text-truncate-2 label-large">@item.BriefIntroduction</div>
                        </div>
                    </div>
                </MDCard>
            </div>
        }

    </CnGalWebSite.Components.Containers.MasaTitleContainer>
}

@code {
    [Parameter]
    public FavoriteObjectType Type { get; set; }
    [Parameter]
    public long Id { get; set; }

    public List<FavoriteFolderOverviewModel> Model = new List<FavoriteFolderOverviewModel>();
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        try
        {
            Model = await _pageModelCatche.GetCache($"api/favorites/GetRelateFavoriteFolders?type={(int)Type}&id={Id}");

            StateHasChanged();
        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取目录失败");
            StateHasChanged();
        }

    }
}
